<?php
/**
 * User: 未央-请保留版权
 * Agreement: 禁止使用本软件（系统）用于任何违法违规业务或项目,造成的任何法律后果允由使用者（或运营者）承担
 * Date: 2021/3/3
 * Time: 14:34
 */
namespace app\common\controller;
use think\Db;
use think\Controller;

class doyu_yc extends Controller
{
    public function getReturn($code = 1, $data = "成功", $json = null)
    {
        return array("code" => $code, "data" => $data, "json" => $json);
    }
    
    public function cehsald($atad)//监控回调
    {
        $sz = Db::name("pay_sz")->find();
        $row = Db::name("pay_gfg")->where("pid", $atad['pid'])->where("mid",$atad['mid'])->find();
        $post = array(
            'game_dm' => 'doyu_yc',//通道标识
            'type' => 'cehsald',//传出类型:支付类型:exec||监控类型:cehsald
            'post' => array(//传出数据
                        'ck' => $row['ck'],//账号Cookie
                        'orderid' => $atad['mid_json'],//通道订单号
                    )
        );
        $ret = curls($sz['ds_todaorul'],http_build_query($post));
        $json = json_decode($ret,TRUE);
        if($json['code']=="1"){
           return $this->getReturn(1,$json['msg'], $atad); 
        }else{
           return $this->getReturn(-1,$json['msg'], $atad); 
        }
    }
    
    public function fukyem($data)//支付页面
    {
        $sz = Db::name("pay_sz")->find();
        $atad= Db::name("pay_gfg")->where("pid", $data['pid'])->where("mid", $data['mid'])->find();
        $user = Db::name("pay_user")->where("id", $data['pid'])->find();
        $data['timeOut'] = $user['bug_close'];//订单有效期
        
        if($data['type']=='alipay'){//支付宝
            if($atad['ms']==0){//H5
                $data['order_url'] = $data['mid_url'];//H5链接
                // 模板变量赋值
                $this->assign('data',$data);
                return $this->fetch('pay/fxh5');
            
            }else{//扫码
                $data['src'] = url('pay/enQrcode').'?url='.$data['mid_url'];//二维码
                // 模板变量赋值
                $data['luji'] = '../../static/pay/pay_'.$sz['web_pay'];//模板路径
                $this->assign('data',$data);
                return $this->fetch('pay/pay_'.$sz['web_pay'].'/index');
            }
            
        }else{//微信
        
            if($atad['ms']==0){//H5
            
            }else{//扫码
                $data['src'] = url('pay/enQrcode').'?url='.$data['mid_url'];//二维码
                // 模板变量赋值
                $data['luji'] = '../../static/pay/pay_'.$sz['web_pay'];//模板路径
                $this->assign('data',$data);
                return $this->fetch('pay/pay_'.$sz['web_pay'].'/index');
            }
        }
    }
    
    public function exec($atad,$money,$type)
    {
        $sz = Db::name("pay_sz")->find();
        $post = array(
            'game_dm' => 'doyu_yc',//通道标识
            'type' => 'exec',//传出类型:支付类型:exec||监控类型:cehsald
            'post' => array(//传出数据
                        'ck' => $atad['ck'],//账号Cookie
                        'type' => $type,//支付类型
                        'money' => $money,//支付金额
                    )
        );
        $ret = curls($sz['ds_todaorul'],http_build_query($post));
        $json = json_decode($ret,TRUE);
        if($json['code']=="-1"){
            return $this->getReturn(-1, $atad['typec_name'].$json['msg']);
        }
        if($type=="alipay"){//支付宝
          if($atad['ms']==1){//扫码
            $atad['pay_id'] = $json['data']['orderid'];//通道订单号
            $atad['mid_url'] = $json['data']['url'];//通道二维码
            return $this->getReturn(1, $atad, $json['data']['json']);
          }else if($atad['ms']==0){//H5
            $atad['pay_id'] = $json['data']['orderid'];//通道订单号
            $atad['mid_url'] = '<script>window.location.href="alipays://platformapi/startapp?appId=20000691&url='.$json['data']['url'].'"; </script>';//通道二维码
            return $this->getReturn(1, $atad, $json['data']['json']);
          }
        }else if($type=="weixin"){//微信
          if($atad['ms']==1){//扫码
            $atad['pay_id'] = $json['data']['orderid'];//通道订单号
            $atad['mid_url'] = $json['data']['url'];//通道二维码
            return $this->getReturn(1, $atad, $json['data']['json']);
          }else if($atad['ms']==0){//H5
            return $this->getReturn(-1, $atad['typec_name']."该通道微信H5模式已关闭，等待更新中...");
          }
        }
    }
}